package com.qianfeng.test.task;

import android.os.AsyncTask;
import android.text.TextUtils;
import android.widget.BaseAdapter;

import com.alibaba.fastjson.JSONObject;
import com.qianfeng.test.bean.AppBean;
import com.qianfeng.test.bean.ShopInfo;
import com.qianfeng.test.bean.gridview_bean.GridBean;
import com.qianfeng.test.bean.gridview_bean.NameInfo;
import com.qianfeng.test.utils.HttpUtils;

import java.util.List;

/**
 * Created by Administrator on 15-7-27.
 */
public class GridViewTask extends AsyncTask<String ,Void,List<NameInfo>> {
    private BaseAdapter baseAdapter;
    private List<NameInfo> gridlist;

    public GridViewTask(BaseAdapter baseAdapter, List<NameInfo> gridlist) {
        this.baseAdapter = baseAdapter;
        this.gridlist = gridlist;
    }

    @Override
    protected List<NameInfo> doInBackground(String... params) {
        String result = HttpUtils.getDataFromService(params[0]);
        if(!TextUtils.isEmpty(result)){
            GridBean grid = JSONObject.parseObject(result, GridBean.class);
            if(grid!=null&&grid.getResult()!=null){//
                gridlist = grid.getResult().getInfo();//
            }
        }
        System.out.print("shopInfoList...."+gridlist);
        return gridlist;
    }
    protected void onPostExecute(List<NameInfo> nameInfos) {
        super.onPostExecute(nameInfos);

        if(nameInfos!=null&&nameInfos.size()>0){
            System.out.print("onPostExecute....进来了");

            gridlist.addAll(nameInfos);
            baseAdapter.notifyDataSetChanged();
        }

    }
}
